

package com.yf.tz.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.alibaba.excel.EasyExcel;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import  com.yf.tz.vo.down.AccountRecordDown;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import java.net.URLEncoder;
import com.yf.tz.vo.down.AccountRecordDown;
import javax.servlet.http.HttpServletResponse;
import java.util.stream.Collectors;
import com.yf.tz.dao.AccountRecordDao;
import com.yf.tz.entity.AccountRecordEntity;
import com.yf.tz.vo.AccountRecordVo;
import com.yf.tz.service.AccountRecordService;
import com.yf.service.impl.BaseServiceImpl;

/**
 * 账户记录Service实现类
 *
 * @author hxf
 * @email 505860922@qq.com
 * @date ${datetime}
 */
@Service
public class AccountRecordServiceImpl extends BaseServiceImpl<AccountRecordEntity> implements AccountRecordService {

    private AccountRecordDao dao;


    @Autowired
    public void setDao(AccountRecordDao dao) {
        this.dao = dao;
        super.setBaseDao(dao);
    }






    @Override
    public List<AccountRecordVo> findVo(AccountRecordVo vo){
        return dao.findVo(vo);
    }

    @Override
    public AccountRecordVo getVo(Long id){
        return dao.getVo(id);
    }



    @Override
    public int saveVo(AccountRecordVo vo){
        return dao.save(vo.getEntity());
    }



    @Override
    public int updateVo(AccountRecordVo vo){
        return dao.update(vo.getEntity());
    }



    @Override
    public void downLoad(HttpServletResponse response, List<AccountRecordVo> list) {
        try {
            List<AccountRecordDown> datas = list.stream().map(item -> new AccountRecordDown(item)).collect(Collectors.toList());
            response.setContentType("application/vnd.ms-excel" );
            response.setCharacterEncoding("utf-8" );
            // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
            String fileName = URLEncoder.encode("测试", "UTF-8" );
            response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx" );
            EasyExcel.write(response.getOutputStream(), AccountRecordDown.class).sheet("模板" ).doWrite(datas);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }




    /**内部方法**/




    /**外部方法实现**/



    @Override
    public AccountRecordEntity findByBusAndOrderNo(Integer bus, String orderNo) {
        return dao.findByBusAndOrderNo(bus,orderNo);
    }

    @Override
    public List<AccountRecordVo> findByUserIdAndType(Long userId, Integer type, String date) {
        return dao.findByUserIdAndType(userId,type,date);
    }
}
